<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Example
 *
 * This is an example of a few basic user interaction methods you could use
 * all done with a hardcoded array.
 *
 * @package		CodeIgniter
 * @subpackage	Rest Server
 * @category	Controller
 * @author		Joomlavui
 * @link		http://joomlavui.info
*/

// This can be removed if you use __autoload() in config.php OR use Modular Extensions
require APPPATH.'/libraries/REST_Controller.php';

class API extends REST_Controller
{
	/**
     * Contrust class
     *  
     * @access public 
     */
    public function __construct() {
		
        parent::__construct();
		$this->load->helper('url');		
        $this->load->library('smarty3', '', 'smarty');
        $this->load->library('captcha');
        $this->load->library('session');
		// load models user,billing
		$this->load->model('kpay/db_user_model');
        $this->user_model		= new db_user_model();
    }	
    // get user detail
    function user_post()
    {	
		// Post value		
		$UserName	= $this->post('UserName');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$UserName or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($UserName.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}
		if (strlen($UserName) > 20 || strlen($UserName) < 5) {
			echo -1;return;
		}
		if (!preg_match('/^[a-z0-9._]+$/', $UserName)) {
			echo -1;return;
		}			
		// 
        $user 		= $this->user_model->getUser($UserName);
        if($user){
            $this->response($user, 200); // 200 being the HTTP response code
        }else{
			echo -2;return;
        }
    }
	// get all users
    function users_post()
    {	
		// post value		
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}		
		// 
        $user 		= $this->user_model->getUsers();
        if($user){
            $this->response($user, 200); // 200 being the HTTP response code
        }else{
			echo -888;return;
        }
    }
	// validate username
    function userValidate_post()
    {	
		// Post value		
		$UserName	= $this->post('UserName');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$UserName or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($UserName.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}	
		if (strlen($UserName) > 20 || strlen($UserName) < 5) {
			echo -1;return;
		}
		if (!preg_match('/^[a-z0-9._]+$/', $UserName)) {
			echo -1;return;
		}	
		// 
        $user 		= $this->user_model->getUser($UserName);
        if($user){
            echo -1;return; // user đã tồn tại trong db
        }else{
			echo 1;return;
        }
    }
    
	// update user info
    function userUpdate_post()
    {	
		// post value		
		$UserName	= $this->post('UserName');
		$Password	= $this->post('Password');
		$Email		= $this->post('Email');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');		
        // check tham số truyền vào
		if(!$UserName or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($UserName.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}
		if (strlen($UserName) > 20 || strlen($UserName) < 5) {
			echo -2;return;
		}
		if (!preg_match('/^[a-z0-9._]+$/', $UserName)) {
			echo -2;return;
		}
		if (preg_match("/^[0-9a-zA-Z]\w+(\.\w+)*\@\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/", $Email) === 0) {
			echo -3;return;
		}
		if (!$Password || strlen($Password) < 6) {
			echo -4;return;
		}
		if ($Password == $UserName){
			echo -5;return;
		}				
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}						
		// đưa thông tin vào params
		$aParamUser=array(
			"time"		=> date("Y-m-d H:i:s"),
			'ip' 		=> $ip
		);		
		// update customer ID for user table
		$aUpdate	= array("time","ip");
		$tmp 		= $this->user_model->insert_onduplicate_update_User($aParamUser,$aUpdate);
		if($tmp < 1){
			echo -2;return;	//UserName không hợp lệ hoặc đã được đăng ký
		}				
		// get user info
		$user 		= $this->user_model->getUser($UserName);
		if($user){			
			$this->response($user, 200); // 200 being the HTTP response code
		}else{
			echo -888;return;	
		}        
    }
	// get all card categories
    function getCardCategories_post()
    {	
		// post value		
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}		
		// 
        $user 		= $this->user_model->getCardCategories();
        if($user){
            $this->response($user, 200); // 200 being the HTTP response code
        }else{
			echo -888;return;
        }
    }
	// get all getCardProviders
    function getCardProviders_post()
    {	
		// post value		
		$catID		= $this->post('catID');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$catID or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($catID.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}
		// check card cat trust
		$ws			= $this->user_model->checkCardCategories($catID);
		if(!$ws){
			echo -1;return; // danh mục card ko tồn tại or ko được public
		}		
		// 
        $user 		= $this->user_model->getCardProviders($catID);
        if($user){
            $this->response($user, 200); // 200 being the HTTP response code
        }else{
			echo -888;return;
        }
    }
	// get all getCardProvider
    function getCardProducts_post()
    {	
		// post value		
		$providerID	= $this->post('providerID');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$providerID or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($providerID.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}
		// check card provider trust
		$ws			= $this->user_model->checkCardProvider($providerID);
		if(!$ws){
			echo -1;return; // danh mục nhà cung cấp ko tồn tại or ko được public
		}		
		// 
        $user 		= $this->user_model->getCardProducts($providerID);
        if($user){
            $this->response($user, 200); // 200 being the HTTP response code
        }else{
			echo -888;return;
        }
    }
	/***********************************************************************/
	// password hashing
	function passwordHashing($password=null)
	{
		// Store the new user's information in the database. 
		$key 				= $this->config->item('encryption_key');
		$salt1		 		= hash('sha512', $key . $password);
		$salt2 				= hash('sha512', $password . $key);
		$hashed_password 	= hash('sha512', $salt1 . $password . $salt2);	
		return $hashed_password;
	}
	// create customer ID
	function createCustomerID($partnerID=null) // gg@,fb@,yh@
	{				
		// custom // exp: zing@9000001
		$prefix			= $partnerID."@"."9".date("Y")."000";// partnerID-@-số may mắn-năm-000-ID gắn liền với record id của user.
		$customerID		= $prefix.$this->db->insert_id();
		return $customerID;
	}
	/***********************************************************************/
	// register user
    function register_post()
    {	
		// post value		
		//$UserName	= $this->post('UserName');
		$UserName	= time();
		$Password	= $this->post('Password');
		$Email		= $this->post('Email');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');		
        // check tham số truyền vào
		if(!$Email or !$Password or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($Email.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		if (!$Password || strlen($Password) < 6) {
			echo -4;return;
		}
		if ($Password == $UserName){
			echo -5;return;
		}
		if($Password){
			$Password = $this->passwordHashing($Password);	
		}	
		// customer ID
		if($wsUserName){
			$partnerPrefix 	= explode("_", $wsUserName);
			$partnerID		= $partnerPrefix[0]; // gg,yh,...
		}else{
			$partnerID		= "mt";
		}
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}
		// check email trùng
		$uEmail		= $this->user_model->checkEmail($Email);
		if($uEmail){
			echo -3;return; // trùng email
		}			
		// đưa thông tin vào params
            $aParamUser=array(                                
                'username' 	=> $UserName,				
				'password'	=> $Password,
				'email' 	=> $Email,
				"created"	=> date("Y-m-d H:i:s"),
				'ip' 		=> $ip
            );		
		// 
        $tmp 			= $this->user_model->insertUser($aParamUser);				
		if($tmp){	
				$customerID		= $this->createCustomerID($partnerID);
				// đưa thông tin vào params
				$aParamUser=array(                                
					'username' 	=> $UserName,
					'customerID'=> $customerID,
					'password'	=> $Password,
					'email' 	=> $Email,
					"created"	=> date("Y-m-d H:i:s"),
					'ip' 		=> $ip
				);		
			// update customer ID for user table
			$aUpdate	= array("customerID","username");
			$tmp1 		= $this->user_model->insert_onduplicate_update_User($aParamUser,$aUpdate);
			if($tmp1<1){
				echo -2;return;	//UserName không hợp lệ hoặc đã được đăng ký
			}				
			// get user info by email
			$user 		= $this->user_model->getUserByEmail($Email);
        	if($user){			
            	$this->response($user, 200); // 200 being the HTTP response code
			}else{
				echo -999;return;	 // đăng ký thành công nhưng ko get dc dữ liệu
			}
        }else{
			echo -888;return;
        }
    }
	// register user by open ID
    function registerOpenID_post()
    {	
		// post value		
		//$UserName	= $this->post('UserName');
		$UserName	= time();
		//$Password	= $this->post('Password');
		$Email		= $this->post('Email');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');		
        // check tham số truyền vào
		if(!$Email or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($Email.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}					
		// customer ID
		if($wsUserName){
			$partnerPrefix 	= explode("_", $wsUserName);
			$partnerID		= $partnerPrefix[0]; // gg,yh,...
		}else{
			$partnerID		= "mt";
		}
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}
		// check email trùng
		/*$uEmail		= $this->user_model->checkEmail($Email);
		if($uEmail){
			echo -3;return; // trùng email
		}*/			
		// đưa thông tin vào params
            $aParamUser=array(                                
                'username' 	=> $UserName,				
				//'password'	=> $Password,
				'emailOpenID' 	=> $Email,
				"created"	=> date("Y-m-d H:i:s"),
				'ip' 		=> $ip
            );		
		// 
        $tmp 			= $this->user_model->insertUser($aParamUser);				
		if($tmp){	
				$customerID		= $this->createCustomerID($partnerID);
				// đưa thông tin vào params
				$aParamUser=array(                                
					'username' 	=> $UserName,
					'customerID'=> $customerID,
					//'password'	=> $Password,
					'emailOpenID' 	=> $Email,
					"created"	=> date("Y-m-d H:i:s"),
					'ip' 		=> $ip
				);		
			// update customer ID for user table
			$aUpdate	= array("customerID","username");
			$tmp1 		= $this->user_model->insert_onduplicate_update_User($aParamUser,$aUpdate);
			if($tmp1<1){
				echo -2;return;	//UserName không hợp lệ hoặc đã được đăng ký
			}				
			// get user info by email
			$user 		= $this->user_model->getUserByEmailOpenID($Email);
        	if($user){			
            	$this->response($user, 200); // 200 being the HTTP response code
			}else{
				echo -999;return;	 // đăng ký thành công nhưng ko get dc dữ liệu
			}
        }else{
			echo -888;return;
        }
    }
	// check login
    function checkLogin_post()
    {	
		// Post value		
		$UserName	= $this->post('UserName');
		$Password	= $this->post('Password');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$UserName or !$Password or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($UserName.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}		
		// 
        $user 		= $this->user_model->checkLogin($UserName,$Password);
        if($user){
            $this->response($user, 200); // 200 being the HTTP response code
        }else{
			echo -1;return;
        }
    }
	// check login by Email
    function checkLoginEmail_post()
    {	
		// Post value		
		$Email		= $this->post('Email');
		$Password	= $this->post('Password');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$Email or !$Password or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($Email.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// get password hash
		if($Password){
			$Password	= $this->passwordHashing($Password);
		}
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}		
		// 
        $user 		= $this->user_model->checkLoginEmail($Email,$Password);
        if($user){
            $this->response($user, 200); // 200 being the HTTP response code
        }else{
			echo -1;return;
        }
    }
	// check UserName
    function checkUserName_post()
    {	
		// Post value		
		$UserName	= $this->post('UserName');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$UserName or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($UserName.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}		
		// 
        $user 		= $this->user_model->checkUserName($UserName);
        if($user){
            $this->response($user, 200); // 200 being the HTTP response code
        }else{
			echo -1;return;
        }
    }
	// check Email
    function checkEmail_post()
    {	
		// Post value		
		$Email		= $this->post('Email');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$Email or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($Email.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}		
		// 
        $user 		= $this->user_model->checkEmail($Email);
        if($user){
            $this->response($user, 200); // 200 being the HTTP response code
        }else{
			echo -1;return;
        }
    }
	// check checkCustomerID
    function checkCustomerID_post()
    {	
		// Post value		
		$CustomerID	= $this->post('CustomerID');
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$CustomerID or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($UserName.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}		
		// 
        $user 		= $this->user_model->checkEmail($Email);
        if($user){
            $this->response($user, 200); // 200 being the HTTP response code
        }else{
			echo -1;return;
        }
    }
	
	//cập nhật điểm người chơi theo từng sự kiện 
	//(chỉ có điểm của sự kiện mới cập nhật riêng, còn lại vàng + xu  là cập nhật chung)	
	function updateScoreUser_post()
    {	
		// Post value	
		$wsUserName	= $this->post('wsUserName');
		$wsPassword	= $this->post('wsPassword');
		$eventShowID= $this->post('eventShowID');
		$ip			= $this->post('ip');
		$Signature 	= $this->post('Signature');
        // check tham số truyền vào
		if(!$eventShowID or !$wsUserName or !$wsPassword or !$Signature){
			echo -110;return;
		}
		// check chữ ký
		$sign	 	= md5($eventShowID.$wsUserName.$wsPassword);
		if($Signature!=$sign){
			echo -102;return;
		}		
		// check ws trust
		$ws			= $this->user_model->checkWebService($wsUserName,$wsPassword);
		if(!$ws){
			echo -100;return;
		}
		// check exists event ID
		$esID		= $this->user_model->checkEventShowID($eventShowID);
		if(!$esID){
			echo -2;return; // EventShowID ko tồn tại.
		}
		// 
        $val 		= $this->user_model->getWinList($eventShowID);		
        if($val){
            $this->response($val, 200); // 200 being the HTTP response code
        }else{
			echo -1;return;
        }
    }
	/////////////////////////////////////////////////////////////////////////
    
    //change password
    function updatePassword_post()
    {
        $wsUserName = $this->post('wsUserName');
        $wsPassWord = $this->post('wsPassWord');
        $Email      = $this->post('Email');
        $Password   = $this->post('Password');
        $newPassword = $this->post('newPassword');
        $Signature   = $this->post('Signature');
        $customerID = $this->post('customerID');
        
        //check tham số truyền vào
        if(!$wsUserName or !$wsPassWord or !$Email or !$Password or !$newPassword)
        {
            echo -110;return;
        }
        //check chữ ký
        $sign	 	= md5($Email.$wsUserName.$wsPassWord);
        if($Signature!=$sign){
                echo -102;return;
        }
        //check password
        if (!$newPassword || strlen($newPassword) < 6) {
                echo -4;return;
        }
        if ($newPassword == $Email){
                echo -5;return;
        }
        if($newPassword){
                $newPassword = $this->passwordHashing($newPassword);	
        }

        $user = $this->user_model->getUserByEmail($Email);
        if($this->passwordHashing($Password)!=$user[0]->password)
        {
            echo -3;return;
        }
        // check ws trust
        $ws			= $this->user_model->checkWebService($wsUserName,$wsPassWord);
        if(!$ws){
                echo -100;return;
        }						
        // đưa thông tin vào params
        $aParamUser=array(
                "customerID"		=> $customerID,
                'password' 		=> $newPassword
        );		
        // update customer ID for user table
        $aUpdate	= array("customerID","password");
        $tmp 		= $this->user_model->insert_onduplicate_update_User($aParamUser,$aUpdate);
        if($tmp < 1){
                echo -2;return;	//UserName không hợp lệ hoặc đã được đăng ký
        }				
        // get user info
        $user 		= $this->user_model->getUserByEmail($Email);
        
        if($user){			
                $this->response($user, 200); // 200 being the HTTP response code
        }else{
                echo -888;return;	
        }
    }
    
    //reset password - forget password - without old password
    function resetPassword_post()
    {
        $wsUserName = $this->post('wsUserName');
        $wsPassWord = $this->post('wsPassWord');
        $Email      = $this->post('Email');
        $newPassword = $this->post('newPassword');
        $Signature   = $this->post('Signature');
        $customerID = $this->post('customerID');
        ///echo '-1000';return;
        //check tham số truyền vào
        if(!$wsUserName or !$wsPassWord or !$Email or !$newPassword)
        {
            echo -110;return;
        }
        //check chữ ký
        $sign	 	= md5($Email.$wsUserName.$wsPassWord);
        if($Signature!=$sign){
                echo -102;return;
        }
        //check password
        if (!$newPassword || strlen($newPassword) < 6) {
                echo -4;return;
        }
        if ($newPassword == $Email){
                echo -5;return;
        }
        if($newPassword){
                $newPassword = $this->passwordHashing($newPassword);	
        }
        
        // check ws trust
        $ws			= $this->user_model->checkWebService($wsUserName,$wsPassWord);
        if(!$ws){
                echo -100;return;
        }						
        // đưa thông tin vào params
        $aParamUser=array(
                "customerID"		=> $customerID,
                'password' 		=> $newPassword
        );		
        // update customer ID for user table
        $aUpdate	= array("customerID","password");
        $tmp 		= $this->user_model->insert_onduplicate_update_User($aParamUser,$aUpdate);
        if($tmp < 1){
                echo -2;return;	//UserName không hợp lệ hoặc đã được đăng ký
        }				
        // get user info
        $user 		= $this->user_model->getUserByEmail($Email);
        
        if($user){			
                $this->response($user, 200); // 200 being the HTTP response code
        }else{
                echo -888;return;	
        }
    }
}